import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()


class Config:
    """配置类"""

    # 项目根路径
    BASE_DIR = Path(__file__).parent.parent
    APP_PATH = str(BASE_DIR)

    # 验证码图片路径
    VERIFY_IMG_DIR = BASE_DIR / "verify_img"

    # Playwright 配置
    BROWSER = os.getenv("BROWSER", "chromium")  # chromium, firefox, webkit
    HEADLESS = os.getenv("HEADLESS", "True").lower() == "true"
    SLOW_MO = int(os.getenv("SLOW_MO", "0"))
    VIEWPORT = {"width": 1920, "height": 1080}

    # 超时时间
    TIMEOUT = 30000  # 30秒
    NAVIGATION_TIMEOUT = 60000  # 60秒

    # 项目配置
    BASE_URL = os.getenv("BASE_URL", "http://tpshop")

    # 重试配置
    MAX_RETRY = 3
    RETRY_DELAY = 1


# 创建必要的目录
Config.VERIFY_IMG_DIR.mkdir(exist_ok=True)

if __name__ == '__main__':
    config = Config()
    print(config.APP_PATH)
